package com.lujianfei.netease_android_mvp.presenter

import com.lujianfei.netease_android_mvp.MainContract
import com.lujianfei.netease_android_mvp.bean.MainBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext

class MainPresenter(view: MainContract.View) : MainContract.Presenter(view) {

    override fun loadData() {
        // 运用协程实现线程的简单调度
        launchOnUI {
            mView?.showLoading()
            val data = withContext(Dispatchers.IO) {
                delay(2000)
                val data = ArrayList<MainBean>()
                for (index in 1..20) {
                    data.add(MainBean(title = "title$index", summary = "summary$index"))
                }
                data
            }
            mView?.setData(data)
            mView?.hideLoading()
        }
    }
}